﻿<UserControl x:Class="StackHash.MainProductList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:StackHash"
        xmlns:vcs="clr-namespace:StackHash.ValueConverters" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MasterResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="Properties" x:Name="commandBindingProperties" CanExecute="commandBindingProperties_CanExecute" Executed="commandBindingProperties_Executed" />
    </UserControl.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" x:Name="Column1" MinWidth="50" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" x:Name="Column3" MinWidth="50" />
        </Grid.ColumnDefinitions>
        <TextBlock Margin="6" FontSize="14" FontWeight="Bold">Mapped Products</TextBlock>
        <ListView Margin="6" Grid.Row="1" Grid.RowSpan="2" Name="listViewProducts" ContextMenuOpening="listViewProducts_ContextMenuOpening" GridViewColumnHeader.Click="listViewProductsHeader_Click" MouseDoubleClick="listViewProducts_MouseDoubleClick" SelectionChanged="listViewProducts_SelectionChanged" SelectionMode="Single">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>            
            </ListView.ItemContainerStyle>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Name="menuItemToggleSyncEnabled" Click="menuItemToggleSyncEnabled_Click" />
                    <MenuItem Command="local:StackHashCommands.SyncProductCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    <MenuItem Command="local:StackHashCommands.ResyncProductCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    <Separator />
                    <MenuItem Header="Open Product Page on WinQual" Name="menuItemOpenProductPage" Click="menuItemOpenProductPage_Click" />
                    <MenuItem Header="Send Product to Plugin" ItemsSource="{Binding ActivePlugins}" Name="menuItemSendProductToPlugin" Click="menuItemSendProductToPlugin_Click">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="{x:Type MenuItem}">
                                <Setter Property="Header" Value="{Binding Name}" />
                                <Setter Property="Tag" Value="{Binding}" />
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                    <MenuItem Header="Copy Product URL to Clipboard" Name="menuItemCopyProductUrl" Click="menuItemCopyProductUrl_Click" />
                    <Separator />
                    <MenuItem Command="local:StackHashCommands.ExportCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                        <MenuItem.Icon>
                            <Image Source="Help\export.png" />
                        </MenuItem.Icon>
                        <MenuItem Command="local:StackHashCommands.ExportProductListCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                        <MenuItem Command="local:StackHashCommands.ExportEventListCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                        <MenuItem Command="local:StackHashCommands.ExportEventListFullCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    </MenuItem>
                    <Separator />
                    <MenuItem Command="Properties" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    <Separator />
                    <MenuItem Header="Clear Selection" Name="menuItemClearSelection" Click="menuItemClearSelection_Click" />
                    <MenuItem Command="local:StackHashCommands.RefreshCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="SynchronizeEnabled" Content="Synchronize" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding SynchronizeEnabled, Converter={StaticResource boolToYesNoConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="Id" Content="ID" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Id}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="Name" Content="Name" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="Version" Content="Version" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Version}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="TotalEvents" Content="Events on WinQual" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TotalEvents, Converter={StaticResource intGeneralDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="TotalStoredEvents" Content="Events in StackHash" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TotalStoredEvents, Converter={StaticResource intGeneralDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="TotalResponses" Content="Responses" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TotalResponses, Converter={StaticResource intGeneralDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="DateCreatedLocal" Content="Created" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DateCreatedLocal, Converter={StaticResource dateTimeDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="DateModifiedLocal" Content="Modified" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DateModifiedLocal, Converter={StaticResource dateTimeDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="LastSynchronizeStartedTime" Content="Last Sync Started" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding LastSynchronizeStartedTime, Converter={StaticResource dateTimeDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="LastSynchronizeCompletedTime" Content="Last Sync Completed" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding LastSynchronizeCompletedTime, Converter={StaticResource dateTimeDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="CabCollectionPolicy" Content="Cab Collection Policy" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding CabCollectionPolicy, Converter={StaticResource cabCollectionPolicyDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="EventCollectionPolicy" Content="Event Collection Policy" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding EventCollectionPolicy, Converter={StaticResource eventCollectionPolicyDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="EventDisplayHitThreshold" Content="Event Filter" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding EventDisplayHitThreshold, Converter={StaticResource displayPolicyDisplayConverter}}" Opacity="{Binding SynchronizeEnabled, Converter={StaticResource falseHalfOpacityConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>                    
                </GridView>
            </ListView.View>
        </ListView>
        
        <GridSplitter Grid.Column="1" Grid.RowSpan="3" Margin="0,6,0,6" ResizeBehavior="PreviousAndNext" Width="3" />
        
        <TextBlock Grid.Column="2" Margin="6" FontSize="14" FontWeight="Bold" Visibility="{Binding ElementName=listViewProducts, Path=SelectedItem, Converter={StaticResource nullVisibleConverter}}">&lt; Select Product</TextBlock>
        <TextBlock Grid.Column="2" Margin="6" FontSize="14" FontWeight="Bold" Visibility="{Binding ElementName=listViewProducts, Path=SelectedItem, Converter={StaticResource nullHiddenConverter}}">
            <TextBlock Text="{Binding ElementName=listViewProducts, Path=SelectedItem.Name}" />
            <TextBlock Text="{Binding ElementName=listViewProducts, Path=SelectedItem.Version}" />
            <TextBlock>: <Hyperlink IsEnabled="{Binding NotBusy}" Name="linkListEvents" Click="linkListEvents_Click">List Events</Hyperlink></TextBlock>
        </TextBlock>
        
        <ScrollViewer Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Margin="0,6,6,6" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
            <WrapPanel Orientation="Horizontal" Margin="0">
                <local:WorldMapControl DataContext="{Binding EventPackages}" x:Name="worldMapControl" CountryDoubleClick="worldMapControl_CountryDoubleClick" />
                <local:PieChartControl x:Name="pieChartOs" ChartTitle="Hits / Operating System" SegmentDoubleClick="pieChartOs_SegmentDoubleClick" />
                <local:DateBarChartControl x:Name="dateChartHits" ChartTitle="Hits / Date" IsProductPageChart="True"  SearchForDate="dateChartHits_SearchForDate" />
            </WrapPanel>
        </ScrollViewer>
       
    </Grid>
</UserControl>
